home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_winsound.py < prev    next >
Text File  |  2005-11-19  |  4KB  |  118 lines

  1. # Ridiculously simple test of the winsound module for Windows.
  2.  
  3. import unittest
  4. from test import test_support
  5. import winsound, time
  6.  
  7. class BeepTest(unittest.TestCase):
  8.  
  9.     def test_errors(self):
  10.         self.assertRaises(TypeError, winsound.Beep)
  11.         self.assertRaises(ValueError, winsound.Beep, 36, 75)
  12.         self.assertRaises(ValueError, winsound.Beep, 32768, 75)
  13.  
  14.     def test_extremes(self):
  15.         winsound.Beep(37, 75)
  16.         winsound.Beep(32767, 75)
  17.  
  18.     def test_increasingfrequency(self):
  19.         for i in xrange(100, 2000, 100):
  20.             winsound.Beep(i, 75)
  21.  
  22. class MessageBeepTest(unittest.TestCase):
  23.  
  24.     def tearDown(self):
  25.         time.sleep(0.5)
  26.  
  27.     def test_default(self):
  28.         self.assertRaises(TypeError, winsound.MessageBeep, "bad")
  29.         self.assertRaises(TypeError, winsound.MessageBeep, 42, 42)
  30.         winsound.MessageBeep()
  31.  
  32.     def test_ok(self):
  33.         winsound.MessageBeep(winsound.MB_OK)
  34.  
  35.     def test_asterisk(self):
  36.         winsound.MessageBeep(winsound.MB_ICONASTERISK)
  37.  
  38.     def test_exclamation(self):
  39.         winsound.MessageBeep(winsound.MB_ICONEXCLAMATION)
  40.  
  41.     def test_hand(self):
  42.         winsound.MessageBeep(winsound.MB_ICONHAND)
  43.  
  44.     def test_question(self):
  45.         winsound.MessageBeep(winsound.MB_ICONQUESTION)
  46.  
  47. class PlaySoundTest(unittest.TestCase):
  48.  
  49.     def test_errors(self):
  50.         self.assertRaises(TypeError, winsound.PlaySound)
  51.         self.assertRaises(TypeError, winsound.PlaySound, "bad", "bad")
  52.         self.assertRaises(
  53.             RuntimeError,
  54.             winsound.PlaySound,
  55.             "none", winsound.SND_ASYNC | winsound.SND_MEMORY
  56.         )
  57.  
  58.     def test_alias_asterisk(self):
  59.         winsound.PlaySound('SystemAsterisk', winsound.SND_ALIAS)
  60.  
  61.     def test_alias_exclamation(self):
  62.         winsound.PlaySound('SystemExclamation', winsound.SND_ALIAS)
  63.  
  64.     def test_alias_exit(self):
  65.         winsound.PlaySound('SystemExit', winsound.SND_ALIAS)
  66.  
  67.     def test_alias_hand(self):
  68.         winsound.PlaySound('SystemHand', winsound.SND_ALIAS)
  69.  
  70.     def test_alias_question(self):
  71.         winsound.PlaySound('SystemQuestion', winsound.SND_ALIAS)
  72.  
  73.     def test_alias_fallback(self):
  74.         # This test can't be expected to work on all systems.  The MS
  75.         # PlaySound() docs say:
  76.         #
  77.         #     If it cannot find the specified sound, PlaySound uses the
  78.         #     default system event sound entry instead.  If the function
  79.         #     can find neither the system default entry nor the default
  80.         #     sound, it makes no sound and returns FALSE.
  81.         #
  82.         # It's known to return FALSE on some real systems.
  83.  
  84.         # winsound.PlaySound('!"$%&/(#+*', winsound.SND_ALIAS)
  85.         return
  86.  
  87.     def test_alias_nofallback(self):
  88.         try:
  89.             winsound.PlaySound(
  90.                 '!"$%&/(#+*',
  91.                 winsound.SND_ALIAS | winsound.SND_NODEFAULT
  92.             )
  93.         except RuntimeError:
  94.             pass
  95.  
  96.     def test_stopasync(self):
  97.         winsound.PlaySound(
  98.             'SystemQuestion',
  99.             winsound.SND_ALIAS | winsound.SND_ASYNC | winsound.SND_LOOP
  100.         )
  101.         time.sleep(0.5)
  102.         try:
  103.             winsound.PlaySound(
  104.                 'SystemQuestion',
  105.                 winsound.SND_ALIAS | winsound.SND_NOSTOP
  106.             )
  107.         except RuntimeError:
  108.             pass
  109.         else: # the first sound might already be finished
  110.             pass
  111.         winsound.PlaySound(None, winsound.SND_PURGE)
  112.  
  113. def test_main():
  114.     test_support.run_unittest(BeepTest, MessageBeepTest, PlaySoundTest)
  115.  
  116. if __name__=="__main__":
  117.     test_main()
  118.